<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/"
      xmlns:xi="http://www.w3.org/2001/XInclude"
      xmlns:mochi="http://www.mochikit.com/">
  <xi:include href="master.html" />

<title>Clusters</title>
<head>
<meta http-equiv="refresh" content="30" /> 

<script type = "text/javascript">
var temp_sort_key = 1; //specify the column to sort when loading the page
</script>

<script type = "text/javascript" src="/cloudcrvjs/sortable_tables.js"></script>
<script type = "text/javascript" src="/cloudcrvjs/ibox.js"></script>
<!--ibox must go after sortable_tables to keep popup windows (possible method overwrite)-->
<script type = "text/javascript">
/* <![CDATA[ */
var timeoutid=-1;

function turnOnRefresh()
{
    // the timeout value should be the same as in the "refresh" meta-tag
    timeoutid=setTimeout( "refresh()", 30*1000)
}

function refresh()
{
    window.location.reload(true)
}

function turnOffRefresh() 
{
    clearTimeout(timeoutid)
}

function ajaxRequest(){
 var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE
 if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
  for (var i=0; i < activexmodes.length; i++){
   try{
    return new ActiveXObject(activexmodes[i])
   }
   catch(e){
    //suppress error
   }
  }
 }
 else if (window.XMLHttpRequest) // if Mozilla, Safari etc
  return new XMLHttpRequest()
 else
  return false
}

function disableStartButton() {
  document.getElementById("start_button").disabled=true
} 

function setClusterTargetSC(clusterid,targetsc) {

var mygetrequest=new ajaxRequest()
mygetrequest.onreadystatechange=function(){
 if (mygetrequest.readyState==4){
  if (mygetrequest.status==200 || window.location.href.indexOf("http")==-1){
    if (mygetrequest.responseText=="True") {
//      alert("Operation Success")
    } else {
      alert("Operation Failed: status="+mygetrequest.status+" response="+mygetrequest.responseText)
    }
  }
  else{
   alert("An error has occured making the request status="+mygetrequest.status+" href="+window.location.href)
  }
  refresh()
 }

}
mygetrequest.open("GET", "/status/setClusterTargetSC?clusterid="+clusterid+"&targetsc="+targetsc, true)
mygetrequest.send(null)
}

addLoadEvent(turnOnRefresh);

/* ]]> */
</script>

</head>

<!--see roles2.html for documentation about how tables are made-->

<body>

<div style="overflow:auto; width:800px; height: 600px;">
<table border = "1" id="sortable_table" class="datagrid">
    <thead>
      <tr>
          <th mochi:format="str" style="cursor:pointer">Name</th>
	  <th mochi:format="str" style="cursor:pointer">Current Status</th>
	  <th mochi:format="str" style="cursor:pointer">Target Status</th>
	  <th mochi:format="str" style="cursor:pointer">Attributes</th>
	  <th mochi:format="str" style="cursor:pointer">Roles</th>
	  <th mochi:format="str" style="cursor:pointer">Action</th>
      </tr>
    </thead> 
    <tbody>
      <div py:for="i in range(0, len(clusters))">
        <tr>
	    <td>
	      ${clusters[i].getAttr("name")}</td>
	    <td bgcolor="${SC_colors_cluster[clusters[i].currentSC % len(SC_colors_cluster)]}">
	      <font color = "black">
	      ${SC_table_cluster[clusters[i].currentSC]}</font></td>
	    <td bgcolor="${SC_colors_cluster[clusters[i].targetSC % len(SC_colors_cluster)]}">
	      <font color = "black">
	      ${SC_table_cluster[clusters[i].targetSC]}</font></td>
	    <td>     
	      <a href = "${'/dispcl/'+clusters[i].getAttr('name')+'/attr'}" rel = "ibox">Show Attr</a></td>
	    <td>
	      <a href = "${'/dispcl/'+clusters[i].getAttr('name')+'/roles'}" rel = "ibox">Show Roles</a></td>
<?python
startButtonValue="N/A"
startButtonEnable="Disabled"
startButtonAction=""
if clusters[i].currentSC==clusters[i].targetSC and clusters[i].currentSC==clusters[i].SC.SC_INITIALIZED:
  startButtonValue="Start"
  startButtonEnable=None
  startButtonAction="setClusterTargetSC(%s,%s)"%(clusters[i].Cluster_ID,str(clusters[i].SC.SC_RUNNING))
elif clusters[i].currentSC==clusters[i].targetSC and clusters[i].currentSC==clusters[i].SC.SC_RUNNING:
  startButtonValue="Stop"
  startButtonEnable=None
  startButtonAction="setClusterTargetSC(%s,%s)"%(clusters[i].Cluster_ID,str(clusters[i].SC.SC_INITIALIZED))
?>
	    <td>
	      <input type = "button" id = "start_button" py:attrs="{ 'disabled':startButtonEnable }" value = "${startButtonValue}" onclick = "turnOffRefresh();disableStartButton();${startButtonAction}"/></td>


<!--turnOffRefresh();disableStartButton();-->

	</tr>
      </div>
    </tbody>
</table>
</div>

</body>

</html>